﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DtsExplorerProject.Helpers;
using System.Reflection;
using System.IO;
using System.Collections;
using System.Xml;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Security.Permissions;
using System.Security.Principal;
using System.Globalization;




namespace DtsExplorerProject
{
    //C:\Users\Administrator\documents\visual studio 2010\Projects\DtsExplorerProject\DtsExplorerProject\Resources\DtsResources.resx
    public partial class Form1 : Form
    {
        IEnumerable<Configuration> list;
        PackageInfo PackageInfo;
        OpenFileDialog openDialog;
        int i = 0;
        ToolStripMenuItem[] submenuarray;
        TreeNode[] subtreenodearray;

        public string FilePath { get; set; }
        public Form1()
        {
            InitializeComponent();
        }
        string[] eventsArray= new string[] {
                    "OnInformation",
                    "OnError",
                    "OnExecStatusChanged",
                    "OnPostExecute",
                    "OnPostValidate",
                    "OnPreExecute",
                    "OnPreValidate",
                    "OnProgress",
                    "OnQueryCancel",
                    "OnTaskFailed",
                    "OnVariableValueChanged",
                    "OnWarning"
                    };
        private void InitilaizeEventsComboBox()
        {
            if (!string.IsNullOrEmpty(FilePath))
            {
                executablesMenu.DropDownItems.AddRange(GetExecutableTaskNamesHelper(ItemType.ToolStripMenuItem) as ToolStripMenuItem[]);
                cmbEvents.Items.AddRange(eventsArray);
            }
        }
        private void InitializeConnection()
        {
            InitializeGridView();
            InitializeStatuBar();
        }

        private void InitializeStatuBar()
        {
            if (!string.IsNullOrEmpty(FilePath))
            {
                PackageInfo = DtsResourcesManager.GetPackageInfo(FilePath, @"DTSConfiguration\DTSConfigurationHeading"); 
                packNameValue.Text = PackageInfo.PacakgeName;
                creationDateValue.Text = PackageInfo.CreationDate;
                ownerValue.Text = PackageInfo.Owner;
            }
          
        }
       
        private void InitializeGridView()
        {
            if (string.IsNullOrEmpty(FilePath))
            {
                list = null;
            }
            else
            {
                list = DtsResourcesManager.Data(FilePath, @"DTSConfiguration\DTSConfigurationHeading"); 
            }
            configGridView.DataSource = list;
        }
   
        private void Initializetreeview()
        {
            if (string.IsNullOrEmpty(FilePath))
            {
                return;
            }
            TreeNode mainNode = new TreeNode(PackageInfo.PacakgeName);

            switch (culture)
            {
                case "fr":
                    InitializeTreeViewHelper(mainNode, "Variables", "Variable du packet", "Gestionaire d'événements", "Variables", "Properiétés", "Evénements",
                     "Gestionaires de connection", "Variables", "Propriétés", "Fournisseurs Log", "Executables");
                    break;
                case "en":
                    InitializeTreeViewHelper(mainNode, "Variables", "Pacakge variables", "Event Handlers", "Variables", "Properties", "Events",
                     "Connection managers", "Variables", "Properties", "Log providers", "Executables");
                    break;
                case "es":
                    InitializeTreeViewHelper(mainNode, "Variables", "Pacakge variables", "Controladores de eventos", "Variables", "Propiedades", "Eventos",
                     "Administradores de conexión", "Variables", "Propiedades", "Proveedores de registro", "Executables");
                    break;
                case "de":
                    InitializeTreeViewHelper(mainNode, "Variablen", "Pacakge variables", "Event Handlers", "Variablen", "Eigenschaften", "Events",
                     "Verbindungs Manager", "Variablen", "Eigenschaften", "Log Provider", "Executables");
                    break; 
                default:
                    InitializeTreeViewHelper(mainNode, "Variables", "Pacakge variables", "Event Handlers", "Variables", "Properties", "Events",
                    "Connection managers", "Variables", "Properties", "Log providers", "Executables");
                    break;
            }
 
            pacakgeExplorer.Nodes.Add(mainNode);
        }

        private void InitializeTreeViewHelper(TreeNode mainNode,params string[]labels)
        {
            TreeNode variablesTreeNode = new TreeNode { Text = labels[0], ToolTipText = labels[1] };
            TreeNode eventHandlersTreeNode = new TreeNode { Text = labels[2], ToolTipText = labels[2] };
            eventHandlersTreeNode.Nodes.Add(labels[3]);
            eventHandlersTreeNode.Nodes.Add(labels[4]);
            eventHandlersTreeNode.Nodes.Add(labels[5]).Nodes.AddRange(EventNodes(eventsArray));
            TreeNode connectionManagersTreeNode = new TreeNode { Text = labels[6], ToolTipText = labels[6] };
            connectionManagersTreeNode.Nodes.Add(labels[7]);
            connectionManagersTreeNode.Nodes.Add(labels[8]);
            TreeNode logProvidersTreeNode = new TreeNode { Text = labels[9], ToolTipText = labels[9] };
            TreeNode executablesTreeNode = new TreeNode { Text = labels[10], ToolTipText = labels[10] };

            TreeNode[] executablesubnodes = GetExecutableTaskNamesHelper(ItemType.TreeNode) as TreeNode[];
            executablesTreeNode.Nodes.AddRange(executablesubnodes);

            mainNode.Nodes.AddRange(new TreeNode[] { 
                variablesTreeNode,
                eventHandlersTreeNode, 
                connectionManagersTreeNode, 
                logProvidersTreeNode, 
                executablesTreeNode });
        }

        private TreeNode[] EventNodes(string[] nodenames)
        {
            TreeNode[] nodesarray = new TreeNode[nodenames.Length];
            for (int i = 0; i < nodenames.Length; i++)
            {
                nodesarray[i] = new TreeNode(nodenames[i]);
            }
            return nodesarray;
        } 
         
        private IEnumerable<string[]> GetSource()
        { 
            Configuration currentConfigRow;
            List<string[]> currentConfigRowParameters;
                currentConfigRowParameters = new List<string[]>();
                if (string.IsNullOrEmpty(FilePath))
                {
                    return null;
                }
                list = DtsResourcesManager.Data(FilePath, @"DTSConfiguration\DTSConfigurationHeading");
                IEnumerator enumerator = list.GetEnumerator();

                string[] array;
                while (enumerator.MoveNext())
                {
                    currentConfigRow = enumerator.Current as Configuration;
                    array = currentConfigRow.Path.Split(new char[] { '\\', '.', '[', ']' }).ExcludeStringNullOrEmpty();
                    currentConfigRowParameters.Add(array);
                } 
            return currentConfigRowParameters;
        }

        
        enum ItemType { ToolStripMenuItem,TreeNode };


        private  object[] GetExecutableTaskNamesHelper(ItemType itemtype)
        {
            List<Configuration> list = FilterGrid(@"\Package\");
            string[] query = (from el in list select el.Path.SubstringExtension(9, el.Path.IndexOf("."))).Distinct().ToArray();
            switch (itemtype)
            {
                case ItemType.ToolStripMenuItem:
                    {
                        submenuarray = new ToolStripMenuItem[query.Count()];

                        for (int index = 0; index < query.Length; index++)
                        {
                            submenuarray[index] = new ToolStripMenuItem(query[index]);
                            submenuarray[index].Tag = query[index];
                            submenuarray[index].MouseDown += new MouseEventHandler(item_MouseDown);
                        }
                        return submenuarray;
                    }

                case ItemType.TreeNode:
                    {
                        subtreenodearray = new TreeNode[query.Count()];

                        for (int index = 0; index < query.Length; index++)
                        {
                            subtreenodearray[index] = new TreeNode(query[index]);
                            subtreenodearray[index].Tag = query[index];
                        }
                        return subtreenodearray;
                    }
                default:
                    return null;
            } 
        }

 #region file menu
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openDialog = new OpenFileDialog();
            openDialog.Filter = "(*.dtsconfig)|*.dtsconfig";
            if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DtsResourcesManager.FilePath = openDialog.FileName;
                FilePath = DtsResourcesManager.FilePath;
            }
            InitializeConnection();
            Initializetreeview();
            InitilaizeEventsComboBox();
        }
#endregion
 #region View Menu
        private void configuredtypeMenu_Click(object sender, EventArgs e)
        {
            ColumnVisibility(configuredtypeMenu,0);
        }
        private void pathMenu_Click(object sender, EventArgs e)
        {
            ColumnVisibility(pathMenu, 1);
        }

        private void valueTypeMenu_Click(object sender, EventArgs e)
        {
            ColumnVisibility(valueTypeMenu, 2);
        }

        private void configuredValueMenu_Click(object sender, EventArgs e)
        {
            ColumnVisibility(configuredValueMenu, 3);
        }
        private void ColumnVisibility(ToolStripMenuItem menuitem, int columnindex)
        {
            bool statue;
            statue = (menuitem.Checked) ? false : true;
            statue = (!menuitem.Checked) ? true : false;
            menuitem.Checked = statue;

            if (statue == true) configGridView.Columns[columnindex].Visible = true;
            else configGridView.Columns[columnindex].Visible = false;
        }
#endregion
 #region Package Menu

        private void packagevariablesMenu_Click(object sender, EventArgs e)
        {
            PackageFilterationHelper(PackageComponents.PackageVariables);
        }  
        private void eventHandlersMenu_Click(object sender, EventArgs e)
        {
            PackageFilterationHelper(PackageComponents.PackageEventHandlers);
        }
        private void connectionManagersMenu_Click(object sender, EventArgs e)
        {
            PackageFilterationHelper(PackageComponents.ConnectionManagers);
        }
        private void logProvidersMenu_Click(object sender, EventArgs e)
        {
            PackageFilterationHelper(PackageComponents.LogProviders);
        }
        private void executablesMenu_Click(object sender, EventArgs e)
        {
            PackageFilterationHelper(PackageComponents.Executables); 
        }
        private void eventHandlersVariablesMenu_Click(object sender, EventArgs e)
        {
            PackageFilterationHelper(PackageComponents.EventHandlerVariables);  
        }
        private void eventHandlersPropertiesMenu_Click(object sender, EventArgs e)
        {
            PackageFilterationHelper(PackageComponents.EventHandlerPorperties);  
        }
        private void connectionmanagersVariablesMenu_Click(object sender, EventArgs e)
        {           
            PackageFilterationHelper(PackageComponents.ConnectionManagerVariables);
        }
        private void connectionManagersPropertiesMenu_Click(object sender, EventArgs e)
        {
            PackageFilterationHelper(PackageComponents.ConnectionManagerProperties);
        }
        private void unfilterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ResetFilter();
        }

        private void ResetFilter()
        {
            configGridView.DataSource = list;
        }
        private void cmbEvents_TextChanged(object sender, EventArgs e)
        {  
            ToolStripComboBox combobox = (ToolStripComboBox)sender;
            string selectedValue = combobox.Text;
            switch (selectedValue)
            {
                case "OnInformation":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                    break;
                case "OnError":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnError");
                    break;
                case "OnExecStatusChanged":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnExecStatusChanged");
                    break;
                case "OnPostExecute":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostExecute");
                    break;
                case "OnPostValidate":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostValidate");
                    break; 
                case  "OnPreExecute":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreExecute");
                    break;     
                case  "OnPreValidate":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreValidate");
                    break;    
                case  "OnProgress":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnProgress");
                    break;    
                case  "OnQueryCancel":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnQueryCancel");
                    break;    
                case   "OnTaskFailed":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnTaskFailed");
                    break;    
                case   "OnVariableValueChanged":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnVariableValueChanged");
                    break;
                case "OnWarning":
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnWarning");
                    break;    
                default:
                    FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                    break;
            }
        }

        private void item_MouseDown(object sender,MouseEventArgs args)
        {
            ToolStripMenuItem local = (ToolStripMenuItem)sender;
            List<Configuration> source = FilterGrid(@"\Package\");
            List<Configuration> query = (from el in source where el.Path.Contains(local.Tag.ToString()) select el).ToList();
            configGridView.DataSource = query;
        }

        private List<Configuration> FilterGrid(params string[] filterValues)
        {
            if (string.IsNullOrEmpty(FilePath))
            {
                return null;  
            }
            var query = from el in list where el.Path.MultiContains(filterValues) select el;
            return query.ToList();
        }

        public enum PackageComponents 
        {
            PackageVariables, 
            PackageEventHandlers, 
            ConnectionManagers,
            LogProviders,
            Executables,
            EventHandlerVariables,
            EventHandlerPorperties,
            ConnectionManagerProperties,
            ConnectionManagerVariables
        };
   
        private void PackageFilterationHelper(PackageComponents Packagecomponents)
        {
            switch (Packagecomponents)
            {
                case PackageComponents.PackageVariables:
                    configGridView.DataSource = FilterGrid("Package.Variables");
                    break;
                case PackageComponents.PackageEventHandlers:
                    configGridView.DataSource = FilterGrid("Package.EventHandlers");
                    break;
                case PackageComponents.ConnectionManagers:
                    configGridView.DataSource = FilterGrid("Connections");
                    break;
                case PackageComponents.LogProviders:
                    configGridView.DataSource = FilterGrid("LogProviders");
                    break;
                case PackageComponents.Executables:
                    configGridView.DataSource = FilterGrid(@"\Package\");
                    break;
                case PackageComponents.EventHandlerVariables:
                     FilterBySubElementHelper(3,"Package.EventHandlers","Variables");
                     break;
                case PackageComponents.EventHandlerPorperties:
                     FilterBySubElementHelper(3,"Package.EventHandlers","Properties");
                     break;
                case PackageComponents.ConnectionManagerVariables:
                     FilterBySubElementHelper(3, "Package.Connections", "Variables");
                     break;
                case PackageComponents.ConnectionManagerProperties:
                     FilterBySubElementHelper(3, "Package.Connections", "Properties");
                     break;
                default:
                    configGridView.DataSource = list;
                    break;
            }
        }    
        private void FilterBySubElementHelper(int position,params string[] parameters)
        {
            if (string.IsNullOrEmpty(FilePath))
            {
                return;   
            }
            IEnumerable<Configuration> source = FilterGrid(parameters[0]);
            List<Configuration> filtredSource = new List<Configuration>();
            string[] array = new string[7];
            foreach (Configuration item in source)
            {
                array = item.Path.Split(new char[] { '\\', '.', '[', ']' }).ExcludeStringNullOrEmpty();
                if (array[position].Equals(parameters[1]))
                {
                    filtredSource.Add(item);
                }
            }
            configGridView.DataSource = filtredSource;
        }
#endregion


        private void PopulateTreeViewHelper(string[] row, ref TreeNode node)
        {
            if (i == row.Count())
            {
                i = 0;
            }
            TreeNode currentNode = new TreeNode(row[i]);
            node.Nodes.Add(currentNode);
            i++;
            if (i < row.Count())
            {
                PopulateTreeViewHelper(row, ref currentNode);
            }
        }
        


        private void pacakgeExplorer_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeView control = (TreeView)sender;
            TreeNode node = control.SelectedNode;
            string label = node.Text;

            if (e.Node.Text==PackageInfo.PacakgeName)
            {
                ResetFilter();
            }

            switch (culture)
            {
                case "fr":
                    {
                        #region fr
                        switch (e.Node.Text)
                        {
                           
                            case "Variables":
                                {
                                    switch (e.Node.Parent.Text)
                                    {
                                        case "Gestionaire de connection":
                                            PackageFilterationHelper(PackageComponents.ConnectionManagerVariables);
                                            break;
                                        case "Gestionaire d'événements":
                                            PackageFilterationHelper(PackageComponents.EventHandlerVariables);
                                            break;
                                        default:
                                            PackageFilterationHelper(PackageComponents.PackageVariables);
                                            break;
                                    }
                                    break;
                                }

                            case "Propriétés":
                                switch (e.Node.Parent.Text)
                                {
                                    case "Gestionaire de connection":
                                        PackageFilterationHelper(PackageComponents.ConnectionManagerProperties);
                                        break;
                                    case "Gestionaire d'événements":
                                        PackageFilterationHelper(PackageComponents.EventHandlerPorperties);
                                        break;
                                    default:
                                        PackageFilterationHelper(PackageComponents.PackageVariables);
                                        break;
                                }
                                break;
                            case "Gestionaire d'événements":
                                PackageFilterationHelper(PackageComponents.PackageEventHandlers);
                                break;
                            case "Evénements":
                                switch (e.Node.Text)
                                {
                                    case "OnInformation":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                    case "OnError":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnError");
                                        break;
                                    case "OnExecStatusChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnExecStatusChanged");
                                        break;
                                    case "OnPostExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostExecute");
                                        break;
                                    case "OnPostValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostValidate");
                                        break;
                                    case "OnPreExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreExecute");
                                        break;
                                    case "OnPreValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreValidate");
                                        break;
                                    case "OnProgress":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnProgress");
                                        break;
                                    case "OnQueryCancel":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnQueryCancel");
                                        break;
                                    case "OnTaskFailed":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnTaskFailed");
                                        break;
                                    case "OnVariableValueChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnVariableValueChanged");
                                        break;
                                    case "OnWarning":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnWarning");
                                        break;
                                    default:
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                }
                                break;
                            case "Gestionaire de connection":
                                PackageFilterationHelper(PackageComponents.ConnectionManagers);
                                break;
                            case "Fournisseurs Log":
                                PackageFilterationHelper(PackageComponents.LogProviders);
                                break;
                            case "Executables":
                                PackageFilterationHelper(PackageComponents.Executables);
                                break;
                            default:
                                ResetFilter();
                                break;
                        }
                        if (e.Node.Parent.Text == "Executables")
                        {
                            FilterBySubElementHelper(1, @"\Package\", e.Node.Text);
                        }
                        #endregion
                        break;
                    }
                case "en":
                    {
                        #region en
                        switch (e.Node.Text)
                        {
                            case "Variables":
                                {
                                    switch (e.Node.Parent.Text)
                                    {
                                        case "Connection managers":
                                            PackageFilterationHelper(PackageComponents.ConnectionManagerVariables);
                                            break;
                                        case "Event Handlers":
                                            PackageFilterationHelper(PackageComponents.EventHandlerVariables);
                                            break;
                                        default:
                                            PackageFilterationHelper(PackageComponents.PackageVariables);
                                            break;
                                    }
                                    break;
                                }

                            case "Properties":
                                switch (e.Node.Parent.Text)
                                {
                                    case "Connection managers":
                                        PackageFilterationHelper(PackageComponents.ConnectionManagerProperties);
                                        break;
                                    case "Event Handlers":
                                        PackageFilterationHelper(PackageComponents.EventHandlerPorperties);
                                        break;
                                    default:
                                        PackageFilterationHelper(PackageComponents.PackageVariables);
                                        break;
                                }
                                break;
                            case "Event Handlers":
                                PackageFilterationHelper(PackageComponents.PackageEventHandlers);
                                break;
                            case "Events":
                                switch (e.Node.Text)
                                {
                                    case "OnInformation":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                    case "OnError":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnError");
                                        break;
                                    case "OnExecStatusChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnExecStatusChanged");
                                        break;
                                    case "OnPostExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostExecute");
                                        break;
                                    case "OnPostValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostValidate");
                                        break;
                                    case "OnPreExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreExecute");
                                        break;
                                    case "OnPreValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreValidate");
                                        break;
                                    case "OnProgress":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnProgress");
                                        break;
                                    case "OnQueryCancel":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnQueryCancel");
                                        break;
                                    case "OnTaskFailed":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnTaskFailed");
                                        break;
                                    case "OnVariableValueChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnVariableValueChanged");
                                        break;
                                    case "OnWarning":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnWarning");
                                        break;
                                    default:
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                }
                                break;
                            case "Connection managers":
                                PackageFilterationHelper(PackageComponents.ConnectionManagers);
                                break;
                            case "Log providers":
                                PackageFilterationHelper(PackageComponents.LogProviders);
                                break;
                            case "Executables":
                                PackageFilterationHelper(PackageComponents.Executables);
                                break;
                            default:
                                ResetFilter();
                                break;
                        }
                        if (e.Node.Parent.Text == "Executables")
                        {
                            FilterBySubElementHelper(1, @"\Package\", e.Node.Text);
                        }
                        #endregion
                        break;
                    }
                case "es":
                    {
                        #region es
                        switch (e.Node.Text)
                        {

                            case "Variables":
                                {
                                    switch (e.Node.Parent.Text)
                                    {
                                        case "Administradores de conexión":
                                            PackageFilterationHelper(PackageComponents.ConnectionManagerVariables);
                                            break;
                                        case "Controladores de eventos":
                                            PackageFilterationHelper(PackageComponents.EventHandlerVariables);
                                            break;
                                        default:
                                            PackageFilterationHelper(PackageComponents.PackageVariables);
                                            break;
                                    }
                                    break;
                                }

                            case "Propiedades":
                                switch (e.Node.Parent.Text)
                                {
                                    case "Administradores de conexión":
                                        PackageFilterationHelper(PackageComponents.ConnectionManagerProperties);
                                        break;
                                    case "Controladores de eventos":
                                        PackageFilterationHelper(PackageComponents.EventHandlerPorperties);
                                        break;
                                    default:
                                        PackageFilterationHelper(PackageComponents.PackageVariables);
                                        break;
                                }
                                break;
                            case "Controladores de eventos":
                                PackageFilterationHelper(PackageComponents.PackageEventHandlers);
                                break;
                            case "Eventos":
                                switch (e.Node.Text)
                                {
                                    case "OnInformation":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                    case "OnError":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnError");
                                        break;
                                    case "OnExecStatusChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnExecStatusChanged");
                                        break;
                                    case "OnPostExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostExecute");
                                        break;
                                    case "OnPostValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostValidate");
                                        break;
                                    case "OnPreExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreExecute");
                                        break;
                                    case "OnPreValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreValidate");
                                        break;
                                    case "OnProgress":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnProgress");
                                        break;
                                    case "OnQueryCancel":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnQueryCancel");
                                        break;
                                    case "OnTaskFailed":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnTaskFailed");
                                        break;
                                    case "OnVariableValueChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnVariableValueChanged");
                                        break;
                                    case "OnWarning":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnWarning");
                                        break;
                                    default:
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                }
                                break;
                            case "Administradores de conexión":
                                PackageFilterationHelper(PackageComponents.ConnectionManagers);
                                break;
                            case "Proveedores de registro":
                                PackageFilterationHelper(PackageComponents.LogProviders);
                                break;
                            case "Executables":
                                PackageFilterationHelper(PackageComponents.Executables);
                                break;
                            default:
                                ResetFilter();
                                break;
                        }
                        if (e.Node.Parent.Text == "Executables")
                        {
                            FilterBySubElementHelper(1, @"\Package\", e.Node.Text);
                        }
                        #endregion
                        break;
                    }
                case "de":
                    {
                        #region de
                        switch (e.Node.Text)
                        {
                            case "Variablen":
                                {
                                    switch (e.Node.Parent.Text)
                                    {
                                        case "Verbindungs Manager":
                                            PackageFilterationHelper(PackageComponents.ConnectionManagerVariables);
                                            break;
                                        case "Event Handlers":
                                            PackageFilterationHelper(PackageComponents.EventHandlerVariables);
                                            break;
                                        default:
                                            PackageFilterationHelper(PackageComponents.PackageVariables);
                                            break;
                                    }
                                    break;
                                }

                            case "Eigenschaften":
                                switch (e.Node.Parent.Text)
                                {
                                    case "Verbindungs Manager":
                                        PackageFilterationHelper(PackageComponents.ConnectionManagerProperties);
                                        break;
                                    case "Event Handlers":
                                        PackageFilterationHelper(PackageComponents.EventHandlerPorperties);
                                        break;
                                    default:
                                        PackageFilterationHelper(PackageComponents.PackageVariables);
                                        break;
                                }
                                break;
                            case "Event Handlers":
                                PackageFilterationHelper(PackageComponents.PackageEventHandlers);
                                break;
                            case "Events":
                                switch (e.Node.Text)
                                {
                                    case "OnInformation":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                    case "OnError":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnError");
                                        break;
                                    case "OnExecStatusChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnExecStatusChanged");
                                        break;
                                    case "OnPostExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostExecute");
                                        break;
                                    case "OnPostValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostValidate");
                                        break;
                                    case "OnPreExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreExecute");
                                        break;
                                    case "OnPreValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreValidate");
                                        break;
                                    case "OnProgress":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnProgress");
                                        break;
                                    case "OnQueryCancel":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnQueryCancel");
                                        break;
                                    case "OnTaskFailed":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnTaskFailed");
                                        break;
                                    case "OnVariableValueChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnVariableValueChanged");
                                        break;
                                    case "OnWarning":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnWarning");
                                        break;
                                    default:
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                }
                                break;
                            case "Verbindungs Manager":
                                PackageFilterationHelper(PackageComponents.ConnectionManagers);
                                break;
                            case "Log Provider":
                                PackageFilterationHelper(PackageComponents.LogProviders);
                                break;
                            case "Executables":
                                PackageFilterationHelper(PackageComponents.Executables);
                                break;
                            default:
                                ResetFilter();
                                break;
                        }
                        if (e.Node.Parent.Text == "Executables")
                        {
                            FilterBySubElementHelper(1, @"\Package\", e.Node.Text);
                        }
                        #endregion
                        break;
                    }
               
                default:
                    {
                        #region en
                        switch (e.Node.Text)
                        {
                            case "Variables":
                                {
                                    switch (e.Node.Parent.Text)
                                    {
                                        case "Connection managers":
                                            PackageFilterationHelper(PackageComponents.ConnectionManagerVariables);
                                            break;
                                        case "Event Handlers":
                                            PackageFilterationHelper(PackageComponents.EventHandlerVariables);
                                            break;
                                        default:
                                            PackageFilterationHelper(PackageComponents.PackageVariables);
                                            break;
                                    }
                                    break;
                                }

                            case "Properties":
                                switch (e.Node.Parent.Text)
                                {
                                    case "Connection managers":
                                        PackageFilterationHelper(PackageComponents.ConnectionManagerProperties);
                                        break;
                                    case "Event Handlers":
                                        PackageFilterationHelper(PackageComponents.EventHandlerPorperties);
                                        break;
                                    default:
                                        PackageFilterationHelper(PackageComponents.PackageVariables);
                                        break;
                                }
                                break;
                            case "Event Handlers":
                                PackageFilterationHelper(PackageComponents.PackageEventHandlers);
                                break;
                            case "Events":
                                switch (e.Node.Text)
                                {
                                    case "OnInformation":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                    case "OnError":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnError");
                                        break;
                                    case "OnExecStatusChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnExecStatusChanged");
                                        break;
                                    case "OnPostExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostExecute");
                                        break;
                                    case "OnPostValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostValidate");
                                        break;
                                    case "OnPreExecute":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreExecute");
                                        break;
                                    case "OnPreValidate":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreValidate");
                                        break;
                                    case "OnProgress":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnProgress");
                                        break;
                                    case "OnQueryCancel":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnQueryCancel");
                                        break;
                                    case "OnTaskFailed":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnTaskFailed");
                                        break;
                                    case "OnVariableValueChanged":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnVariableValueChanged");
                                        break;
                                    case "OnWarning":
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnWarning");
                                        break;
                                    default:
                                        FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
                                        break;
                                }
                                break;
                            case "Connection managers":
                                PackageFilterationHelper(PackageComponents.ConnectionManagers);
                                break;
                            case "Log providers":
                                PackageFilterationHelper(PackageComponents.LogProviders);
                                break;
                            case "Executables":
                                PackageFilterationHelper(PackageComponents.Executables);
                                break;
                            default:
                                ResetFilter();
                                break;
                        }
                        if (e.Node.Parent.Text == "Executables")
                        {
                            FilterBySubElementHelper(1, @"\Package\", e.Node.Text);
                        }
                        #endregion
                        break;              
                    } 
                    
                    
            }
        }

        //private void pacakgeExplorer_AfterSelectHelper(TreeViewEventArgs e,params string[] labels)
        //{
        //            #region en
        //            switch (e.Node.Text)
        //            {
        //                case "Variables":
        //                    {
        //                        switch (e.Node.Parent.Text)
        //                        {
        //                            case "Connection managers":
        //                                PackageFilterationHelper(PackageComponents.ConnectionManagerVariables);
        //                                break;
        //                            case "Event Handlers":
        //                                PackageFilterationHelper(PackageComponents.EventHandlerVariables);
        //                                break;
        //                            default:
        //                                PackageFilterationHelper(PackageComponents.PackageVariables);
        //                                break;
        //                        }
        //                        break;
        //                    }

        //                case "Properties":
        //                    switch (e.Node.Parent.Text)
        //                    {
        //                        case "Connection managers":
        //                            PackageFilterationHelper(PackageComponents.ConnectionManagerProperties);
        //                            break;
        //                        case "Event Handlers":
        //                            PackageFilterationHelper(PackageComponents.EventHandlerPorperties);
        //                            break;
        //                        default:
        //                            PackageFilterationHelper(PackageComponents.PackageVariables);
        //                            break;
        //                    }
        //                    break;
        //                case "Event Handlers":
        //                    PackageFilterationHelper(PackageComponents.PackageEventHandlers);
        //                    break;
        //                case "Events":
        //                    switch (e.Node.Text)
        //                    {
        //                        case "OnInformation":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
        //                            break;
        //                        case "OnError":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnError");
        //                            break;
        //                        case "OnExecStatusChanged":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnExecStatusChanged");
        //                            break;
        //                        case "OnPostExecute":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostExecute");
        //                            break;
        //                        case "OnPostValidate":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnPostValidate");
        //                            break;
        //                        case "OnPreExecute":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreExecute");
        //                            break;
        //                        case "OnPreValidate":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnPreValidate");
        //                            break;
        //                        case "OnProgress":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnProgress");
        //                            break;
        //                        case "OnQueryCancel":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnQueryCancel");
        //                            break;
        //                        case "OnTaskFailed":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnTaskFailed");
        //                            break;
        //                        case "OnVariableValueChanged":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnVariableValueChanged");
        //                            break;
        //                        case "OnWarning":
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnWarning");
        //                            break;
        //                        default:
        //                            FilterBySubElementHelper(2, "Package.EventHandlers", "OnInformation");
        //                            break;
        //                    }
        //                    break;
        //                case "Connection managers":
        //                    PackageFilterationHelper(PackageComponents.ConnectionManagers);
        //                    break;
        //                case "Log providers":
        //                    PackageFilterationHelper(PackageComponents.LogProviders);
        //                    break;
        //                case "Executables":
        //                    PackageFilterationHelper(PackageComponents.Executables);
        //                    break;
        //                default:
        //                    ResetFilter();
        //                    break;
        //            }
        //            if (e.Node.Parent.Text == "Executables")
        //            {
        //                FilterBySubElementHelper(1, @"\Package\", e.Node.Text);
        //            }
        //            #endregion
        //}

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            About about = new About();
            about.ShowInTaskbar = false;
            about.ShowDialog();
        }
    }
}
